#ifndef __BSP_H__
#define __BSP_H__

#include <stdint.h>      // IWYU pragma: export

#define HALL_IRQ_PRIORITY 0
#define ADC_IRQ_PRIORITY 1
#define PWM_BRAKE_IRQ_PRIORITY 2
#define TIMER_UP_IRQ_PRIORITY 2
#define ENC_TIMER_IRQ_PRIORITY 2
#define ENC_PWM_IRQ_PRIORITY 2
#define SCHED_TIMER_IRQ_PRIORITY 3
#define ENC_I_EXIT_IRQ_PRIORITY 4
#define CAN_IRQ_PRIORITY       5
#define UART_IRQ_PRIORITY      5 
#define RTC_IRQ_PRIORITY       6
#define ENC_OTHER_IRQ_PRIORITY 7
#define LOW_IRQ_PRIORITY       14
#define SYSTICK_IRQ_PRIOTIRY   15

#define CONFIG_ENCODER_MPS 1
#define CONFIG_ENCODER_MT  2
#define CONFIG_ENCODER_AMS 3
#define CONFIG_ENCODER_SIMULINK 4

#define ENCODER_TIMER_DIR_DOWN 1
#define ENCODER_TIMER_DIR_UP 2

#define INVALD_PIO 0xFFFFFFFF

#if defined(STM32F405xx)
#include "bsp/stm32/stm32f4xx_board.h" // IWYU pragma: export
#elif defined(USE_MEX_CMD)
#include <unistd.h>
#include "simulation/sim_bsp.h"  // IWYU pragma: export
#endif
#include "bsp/cpu_ticks.h"

/* 相电流采样，采集哪两个相 */
#ifndef CONFIG_PHASE_CURRENT_PHASE_AB
#define CONFIG_PHASE_CURRENT_PHASE_AB 0
#endif
#ifndef CONFIG_PHASE_CURRENT_PHASE_AC
#define CONFIG_PHASE_CURRENT_PHASE_AC 0
#endif
#ifndef CONFIG_PHASE_CURRENT_PHASE_BC
#define CONFIG_PHASE_CURRENT_PHASE_BC 0
#endif
#ifndef CONFIG_PHASE_CURRENT_PHASE_ABC
#define CONFIG_PHASE_CURRENT_PHASE_ABC 0
#endif

/* ADC 电流采样offset离中心点的大小，超过这个大小需要报错 */
#ifndef CONFIG_ADC_OFFSET_TOLERANCE
#define CONFIG_ADC_OFFSET_TOLERANCE 50
#endif
/* 相电流采样极性，是取反还是正, 取决硬件采样电路 (1/-1) */
#ifndef CONFIG_CURRENT_POLARITY
#define CONFIG_CURRENT_POLARITY 1.0f
#endif

/* 母线采样电流极性，取决于采样电路 */
#ifndef CONFIG_DC_CURR_POLARITY
#define CONFIG_DC_CURR_POLARITY 1.0f
#endif

/* 编码器的方向和电机转动方向是否一致 */
#ifndef CONFIG_ENCODER_CC_INVERT
#define CONFIG_ENCODER_CC_INVERT 0
#endif

/* 编码器是否使用abi接口的编码器,可以配合pwm或者spi定位初始位置 */
#ifndef CONFIG_ENCODER_ABI
#define CONFIG_ENCODER_ABI 0
#endif

/* 编码器是否使用abs接口的编码器(spi/i2c接口),使用最简单，但是需要考虑i2c/spi的传输问题 */
#ifndef CONFIG_ENCODER_ABS
#define CONFIG_ENCODER_ABS 0
#endif

#ifndef CONFIG_ENCODER_SPI
#define CONFIG_ENCODER_SPI 0
#endif

#ifndef CONFIG_ENCODER_PWM
#define CONFIG_ENCODER_PWM 0
#endif

/* 串口驱动的收发缓存大小 */
#ifndef CONFIG_UART_TX_BUFFER_SIZE
#define CONFIG_UART_TX_BUFFER_SIZE 4096
#endif
#ifndef CONFIG_UART_RX_BUFFER_SIZE
#define CONFIG_UART_RX_BUFFER_SIZE 512
#endif

#ifndef CONFIG_BOARD_COM_UART
#define CONFIG_BOARD_COM_UART 0
#endif

#ifndef CONFIG_BOARD_COM_CAN
#define CONFIG_BOARD_COM_CAN 0
#endif

#endif /* __BSP_H__ */
